//
//  SXTopicDetailsTableViewCell.m
//  ShiXun
//
//  Created by lanou on 15/10/28.
//  Copyright © 2015年 张琪. All rights reserved.
//

#import "SXTopicDetailsTableViewCell.h"
#import "UIImageView+WebCache.h"

@implementation SXTopicDetailsTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        _avatar_urlImage = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, 30, 30)];
        _avatar_urlImage.layer.masksToBounds = YES;
        _avatar_urlImage.layer.cornerRadius = 15;
        [self.contentView addSubview:_avatar_urlImage];
        
        _screen_nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 10, kScreenWidth / 2, 30)];
        _screen_nameLabel.font = [UIFont systemFontOfSize:14];
        [self.contentView addSubview:_screen_nameLabel];
        
        _contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 50, kScreenWidth - 20, 30)];
        _contentLabel.numberOfLines = 0;
        _contentLabel.font = [UIFont systemFontOfSize:16];
        [self.contentView addSubview:_contentLabel];
  
    }
    return self;
}

// 赋值
- (void)setConfigureModel:(SXTopicListModel *)configureModel
{
    _configureModel = configureModel;
    [_avatar_urlImage sd_setImageWithURL:[NSURL URLWithString:_configureModel.userModel.avatar_url] placeholderImage:[UIImage imageNamed:@"SX-placeholder"]];
    _screen_nameLabel.text = _configureModel.userModel.screen_name;
    _contentLabel.text = _configureModel.content;
    _contentLabel.frame = CGRectMake(10, 50, kScreenWidth - 20, [SXTopicDetailsTableViewCell heightOfContent:_contentLabel.text]);
    
}
// 自适应高度
+ (CGFloat)heightOfContent:(NSString *)content
{
    NSDictionary *dic = [NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:16] forKey:NSFontAttributeName];
    CGRect bounds = [content boundingRectWithSize:CGSizeMake(kScreenWidth - 20, 0) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:dic context:nil];
    return bounds.size.height;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
